package eleTrain.eleDBReader;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Random;

import eleTrain.poker.EleTisch;

public abstract class DBReader {

	protected Connection conn;

	protected int anzHHs;

	protected Random random = new Random();

	public DBReader(String db, String user, String pw, String hhTableSeq) {
		try {
			Class.forName("org.postgresql.Driver");
			conn = DriverManager.getConnection("jdbc:postgresql://localhost/"
					+ db, user, pw);
			Statement st = conn.createStatement();
			String q = "SELECT last_value FROM " + hhTableSeq;
			ResultSet rs = st.executeQuery(q);
			if (rs.next()) {
				anzHHs = rs.getInt(1);
			} else {
				System.err.println("DBReader(): Error setzen von anzHHs");
				System.exit(-1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public abstract EleHH getRandomGame(EleTisch tisch);

	public abstract EleHH getNextGame();

}
